{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7a25336e-3747-497a-9a57-8b0b3cf7d3d4",
   "metadata": {},
   "source": [
    "# Workshop Cloud Data integration #\n",
    "\n",
    "We will start with the installation of the Denodo components."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17d62136-1544-4137-99c2-bab2b3965a8a",
   "metadata": {},
   "outputs": [],
   "source": [
    "pip install --upgrade denodo-sqlalchemy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a1e76bc-7761-4c3a-a3d9-a8d61e6eb5cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "pip install ipython-sql==0.4.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6fe8d1c-dcc2-439d-ad22-36f0a1f3b92b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# use the ipython SQL extenstion\n",
    "%load_ext sql"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40e7221a-10e0-44b6-afb0-c58c6f772ef3",
   "metadata": {},
   "source": [
    "### Connect with a Denodo database using the SQLAlchemy URL pattern for Denodo dialect ###\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d786e0a-7c43-419d-a447-c5cf59a486cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "%sql denodo://admin:admin@vdp:9996/denodo_hol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd53b495-84bd-4a67-8e4a-6656544c0e7d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# importing pre-packeged python libraries which will be used in this exercies\n",
    "\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aec0a918-e292-43bb-9e06-1610c509eeba",
   "metadata": {},
   "source": [
    "#### Importing pre-packaged python libraries which will be used in this exercies ####"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f6e32a7-00b3-40b0-9d75-ba39b71e0973",
   "metadata": {},
   "outputs": [],
   "source": [
    "# we will create a dataframe and load the data into the dataframe\n",
    "\n",
    "data = %sql select c_customer_sk, total_sales from denodo_hol.sales_by_customer \n",
    "df = pd.DataFrame(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c88ee93-e05d-49a1-9689-a11fe357e4d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "#introspecting results of the dataframe\n",
    "\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4eac3539-7b9e-4668-92dc-8a3b12a2ddf8",
   "metadata": {},
   "source": [
    "#### Printing the output ####"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd410122-d50c-422c-84fb-9008a85f5903",
   "metadata": {},
   "outputs": [],
   "source": [
    "#create the bar chart\n",
    "\n",
    "#create the buckets\n",
    "bins = [100,200,300,400,500,600,700,800,900,1000,1100]\n",
    "\n",
    "#plot the total sales for each bucket\n",
    "plt.hist(df.total_sales, bins, histtype='bar')\n",
    "plt.xlabel('total_sales in USD') \n",
    "plt.ylabel('number of customers')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
